package com.example.jpa.springbootjpa.service;

import com.example.jpa.springbootjpa.domian.Cat;
import com.example.jpa.springbootjpa.repository.Cat2Repostitory;
import com.example.jpa.springbootjpa.repository.CatRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import javax.transaction.Transactional;

/**
 * @author kalista
 * @version 1.0.0
 *
 * /**
 * save,update ,delete 方法需要绑定事务.
 *
 * 使用@Transactional进行事务的绑定.
 *
 * @param
 */

@Service
public class CatService {

     @Resource
    private CatRepository catRepository;

     @Resource
     private Cat2Repostitory cat2Repostitory;



     public Cat query(String CatName){
         return cat2Repostitory.findByCatName(CatName);
     }

    //保存数据.
    @Transactional
    public void save(Cat cat){
        catRepository.save(cat);
    }

    //删除数据》
    @Transactional
    public void delete(int id){
        catRepository.delete(id);
    }

    //查询数据.
    public Iterable<Cat> getAll(){
        return catRepository.findAll();
    }
}
